package com.xs.gis.domain.geojson;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import java.io.Serializable;

/**
 * @program: cdgis_geotoolsplus
 * @description:
 * @author: w
 * @create: 2023-08-17 14:55
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GeoCrsProperties implements Serializable {

    private String name;


    /**
     * 获得epsgCode不使用get
     * @return
     */
    @JsonIgnore
   public String getEpsgCode(){
        try {
            CoordinateReferenceSystem crs = CRS.decode(name);
            return CRS.lookupEpsgCode(crs,false).toString();
        } catch (FactoryException e) {
            throw new RuntimeException(e);
        }
    }

    /***
     * 获得epsg 不使用get 否则sjon
     * @return
     */
    @JsonIgnore
    public String getEpsg(){
        return name;
    }
}
